<template>
	<view style="">
		<view class="all_project_head_btn" style="">
			<project-button :projectId="project_id" stageName="外部审查"></project-button>
			<step-button :approvalLog="addFormData.approval_log" :processList="stepProcessList"
				v-if="addFormData.approval_log != null" ></step-button>
		</view>
		<form action="">
			<!-- 项目名称 -->
			<view class="info_item" style="border: 0;">
				<text class="all_text_title">项目名称</text>
				<textarea disabled v-model="S_project_name" maxlength="-1"
				:class="true?'all_new_input_disable_style':'all_new_input_style'"
					auto-height="true" style="width: 95%;padding: 18rpx;"
					 />
			</view>
			<!-- 附件上传提示 -->
			<view class="info_item" style="border-bottom: 0; color: #40A0F2;font-size: 26rpx;">
				*请上传评审意见（若项目不需要评审，可以直接提交）*
			</view>
			<!-- 附件上传 -->
			<view class="info_item" style="border: 0;">
				<upload-file :isSubmit="isSubmit" :imgList="addFormData.annex" :detailsImgList="detailsImgList"
					@my-upload-change="upLoadChange"></upload-file>
			</view>
			<!-- 审批备注 -->
			<view class="info_item" v-if="addFormData.is_approve == 1 && details_project_status == '33'"
				style="border-bottom: 0;">
				<text class="all_text_title">审批备注</text>
				<textarea v-model="approval_remark" class="textera" maxlength="-1"
					auto-height="true" />
			</view>
			<!-- 底部按钮 -->
			<view class="bottom">
				<view v-if="addFormData.is_edit != '1'">
					<button class="bottom_btn" style="background: #CCCCCC; width: 380rpx;" form-type="reset"
						@click="handleSubmit('1')">
						保存草稿
					</button>
					<button class="bottom_btn"
						style="background: linear-gradient(0deg, #037CE3, #2EB3FF); margin-top: -88rpx;margin-left: 50%;"
						form-type="submit" @click="handleSubmit('0')">
						提交
					</button>
				</view>
				
				<!-- 可撤回时显示 -->
				<view class="bottom" v-if="addFormData.is_edit == 1 && addFormData.withdraw_status == 1 && addFormData.is_approve != 1">
					<button
						class="bottom_btn"
						@click="handleWithdraw()"
						style="background: #DD524D; width: 100%;"
						form-type="reset"
					>
						撤回
					</button>
				</view>
				
				<view v-if="addFormData.is_approve == 1 && details_project_status == '33' && addFormData.withdraw_status != 1">
					<button class="bottom_btn" style="background: #CCCCCC; width: 380rpx;" form-type="reset"
						@click="handleExamine('-1')">
						驳回
					</button>
					<button class="bottom_btn"
						style="background: linear-gradient(0deg, #037CE3, #2EB3FF); margin-top: -88rpx;margin-left: 50%;"
						form-type="submit" @click="handleExamine('1')">
						审批通过
					</button>
				</view>
				
				<!-- 可撤回时显示 -->
				<view class="bottom2" v-if="addFormData.is_approve == 1 && addFormData.withdraw_status == 1">
					<button
						class="bottom_btn2"
						@click="handleWithdraw()"
						style="background: #FF5A5F; margin-left: 0;"
						form-type="reset"
					>
						撤回
					</button>
					<button
						class="bottom_btn2"
						@click="handleExamine('-1')"
						style="background: #CCCCCC;margin-left: 33%;"
						form-type="reset"
					>
						驳回
					</button>
					<button
						class="bottom_btn2"
						style="background: linear-gradient(0deg, #037CE3, #2EB3FF);margin-left: 66%;"
						@click="handleExamine('1')"
						form-type="submit"
					>
						审批通过
					</button>
				</view>
				
			</view>
		</form>
	</view>
</template>

<script>
	import xiaolu from '@/components/xiaolu-signature/index.vue';
	import UploadFile from '@/components/upload-file.vue';
	import ProjectButton from '@/components/project-button.vue';
	import StepButton from '@/components/step-button.vue';
	export default {
		components: {
			UploadFile,
			ProjectButton,
			StepButton,
			xiaolu
		},
		data() {
			return {
				stepProcessList:{
						stage_code:'',
						project_id:''
						},
				addFormData: {
					annex: []
				},
				S_project_name: '',
				isSubmit: true,
				detailsImgList: [],
				submitImgList: [],
				approval_remark: '',
				details_project_status: '',
				token: '',
				member_id: '',
				company_id: '',
				project_id: '',
			};
		},
		async onLoad(options) {
			this.token = uni.getStorageSync('btlh_process_token') || '';
			this.member_id = uni.getStorageSync('btlh_process_member_id') || '';
			this.company_id = uni.getStorageSync('bthl_process_LoginCompanyId') || '';

			this.details_project_status = options.details_project_status || '';
			this.project_id = options.project_id || '';
			if (this.project_id) {
				this.getProjectDetails();
			}
		},
		// 开启微信发送给朋友
		//#ifdef MP-WEIXIN
		onShareAppMessage() {
			return {
				title:this.addFormData.project_name,
				path: '/packageProject/pages/project/threeCheck/externalCheck?project_id=' + this.project_id +
					'&details_project_status=' + this.details_project_status
			}
		},
		//#endif
		methods: {
			// 点击撤回
			async handleWithdraw(){
				const { data: res } = await this.$myRequest({
					url: 'Project/withdraw',
					method: 'GET',
					data: {
						member_id: this.member_id,
						token: this.token,
						company_id: this.company_id,
						project_id:this.project_id
					}
				});
				if (res.code != 200)
					return uni.showToast({
						title: res.datas.msg,
						icon: 'none'
					});
					uni.navigateBack({
						delta:1
					})
			},
			// 审批
			async handleExamine(val) {
				const {
					data: res
				} = await this.$myRequest({
					url: 'Project/ereview_approval',
					method: 'POST',
					data: {
						member_id: this.member_id,
						token: this.token,
						company_id: this.company_id,

						project_id: this.project_id,
						approval_status: val,
						remark: this.approval_remark
					}
				});
				if (res.code != 200)
					return uni.showToast({
						title: res.datas.msg,
						icon: 'none'
					});
				uni.showToast({
					title: res.datas.msg,
					icon: 'none'
				});
				/* uni.redirectTo({
					url: `/packageProject/pages/project/projectManagement`
				}); */
				uni.navigateBack({
					delta: 1
				})
			},
			// 编辑提交
			async handleSubmit(val) {
				if (this.date != '选择时间') {
					this.addFormData.notice_time = this.date
				}
				const {
					data: res
				} = await this.$myRequest({
					url: 'Project/ereview',
					method: 'POST',
					data: {
						member_id: this.member_id,
						token: this.token,
						company_id: this.company_id,
						project_id: this.project_id,

						is_draft: val,

						annex: JSON.stringify(this.submitImgList),
					}
				});
				if (res.code != 200)
					return uni.showToast({
						title: res.datas.msg,
						icon: 'none'
					});
				uni.showToast({
					title: res.datas.msg,
					icon: 'none'
				});
				/* uni.redirectTo({
					url: `/packageProject/pages/project/projectManagement`
				}); */
				uni.navigateBack({
					delta: 1
				})
			},
			// 获取详情
			async getProjectDetails() {
				const {
					data: res
				} = await this.$myRequest({
					url: 'Project/ereview_detail',
					method: 'POST',
					data: {
						member_id: this.member_id,
						token: this.token,
						company_id: this.company_id,

						project_id: this.project_id
					}
				});
				if (res.code != 200)
					return uni.showToast({
						title: res.datas.msg,
						icon: 'none'
					});
				// 判断是否首次进入次流程
				if (res.datas.info.is_new != 1) {
					this.addFormData = res.datas.info;
				}else{
				this.addFormData.is_edit = res.datas.info.is_edit
			}
				// 判断禁用
				if (this.addFormData.is_draft != '1' && this.addFormData.is_edit == '1') {
					this.isSubmit = false;
				}
				this.stepProcessList.project_id = this.addFormData.project_id;
				this.stepProcessList.stage_code = this.addFormData.project_status;
				// 禁用值
				this.S_project_name = res.datas.info.project_name;

				// 处理文件
				if (this.addFormData.annex) {
					this.detailsImgList = this.addFormData.annex;
					this.submitImgList = this.addFormData.annex;
				}
				console.log('外部审查', this.addFormData);
			},
			// 文件上传
			upLoadChange(data) {
				console.log('文件列表', data);
				this.submitImgList = data;
			},
			// 点击返回
			back() {
				// uni.navigateBack({
				// 	delta: 1
				// });
				uni.redirectTo({
					url: '/packageProject/pages/project/projectManagement'
				})
			}
		}
	};
</script>

<style lang="scss">
	.bottom2 {
			width: 100%;
		}
	.bottom_btn2 {
			width: 34%;
			height: 88rpx;
			border-radius: 0;
			position: fixed;
			bottom: 0;
			font-size: 32rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #ffffff;
			z-index: 999;
		}		
			
	
	.fbtn {
		position: fixed;
		left: 592rpx;
		bottom: 120rpx;
		z-index: 5;

		image {
			width: 134rpx;
			height: 134rpx;
		}
	}

	.file_name {
		font-size: 26rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #999999;
		margin-left: 19rpx;
	}

	.uptext {
		font-size: 20rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #128bf1;
		margin-left: 10rpx;
	}

	.bottom {
		width: 100%;
		z-index: 100;
		position: fixed;
		bottom: 0;
	}

	.bottom_btn {
		width: 375rpx;
		height: 88rpx;
		margin-left: 0;
		border-radius: 0;
		font-size: 32rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #ffffff;
	}

	.info_item {
		width: 690rpx;
		height: auto;
		border-bottom: 1rpx solid #e3e3e3;
		margin-left: 30rpx;
		margin-top: 44rpx;
	}

	.head_text {
		width: 100%;
		height: 128rpx;
		font-size: 36rpx;
		font-family: PingFang SC;
		font-weight: bold;
		color: #333333;
		line-height: 160rpx;
		text-align: center;
	}

	.textera {
		width: 690rpx;
		height: 225rpx;
		background: #f7f7f7;
		margin-top: 30rpx;
		padding-top: 20rpx;
		padding-bottom: 20rpx;
	}
</style>
